package com.ztc.mapper;
import com.ztc.beans.Book;
import com.ztc.beans.Hobby;
import com.ztc.beans.Role;
import com.ztc.beans.User;
import com.ztc.service.UserService;
import com.ztc.util.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    public List<User> getUser() {
        return userMapper.getUser();
    }

    public  boolean getusername(String username){
        User is = userMapper.getusername(username);

        if (is != null){
            return true;
        }
        return false;
    };
    public User Login(@Param("username") String username, @Param("password") String password) {
        return userMapper.Login(username, password);
    };
    public User register(String username){
        return userMapper.register(username);
    };
    public void adduser(User user) {
        userMapper.addUser(user);
    };
    public void borrowBook(@Param("book") Book book, @Param("user") User user, @Param("day") Timestamp day, @Param("day2") int day2) {
        userMapper.borrowBook(book, user, day, day2);
    };
    public void upBookBsum(Book book){
        userMapper.upBookBsum(book);
    };
    public List<Book> getbook() {
        return userMapper.getbook();
    };
    public void returnBook(Book book, User user){
        userMapper.returnBook(book, user);
    };
    public List<User> getusers2(String mname, String mage, String msex, String mrid, Page page){
        HashMap map = new HashMap();
        map.put("mname",mname);
        map.put("mage",mage);
        map.put("msex",msex);
        map.put("mrid",mrid);
        map.put("page",page);
        int offset = page.getPageSize() * (page.getCurrentPage() - 1);
        map.put("offset", offset);
        map.put("pageSize", page.getPageSize());
        List<User> ulist = userMapper.getusers2(map);
        return ulist;
    };
    public List<User> getusers(){
        return userMapper.getusers();
    };
    public List<User> getusers(Page page){
        HashMap map = new HashMap();
        int offset = page.getPageSize() * (page.getCurrentPage() - 1);
        map.put("offset", offset);
        map.put("pageSize", page.getPageSize());
        List<User> list = userMapper.getusers(map);
        return list;
    };
    public List<Role> getroles(){
        return userMapper.getroles();
    };
    public List<Hobby> gethobbys(){
        return userMapper.gethobbys();
    };
    public User getUserId(String id){
        return userMapper.getUserId(id);
    };
    public void updateuser(User user){
        userMapper.updateuser(user);
    };
    public void deUser(@Param("id") int i){
        userMapper.deUser(i);
    };
    public void zcadduser2(User user){
        userMapper.zcadduser2(user);
    };
    public boolean getusername2(String username){
        User user = userMapper.getusername2(username);
        if(user!=null&&!user.equals("")){
            return true;
        }
        return false;
    };
    public boolean getusername3(String username){
        return userMapper.getusername3(username);
    };
    public List<User> getusers2(HashMap map){
        return userMapper.getusers2(map);
    };
    public int getUserSum(@Param("name") String name,@Param("age") String age,@Param("sex") String sex,@Param("rid") String rid){
        return userMapper.getUserSum(name,age,sex,rid);
    };
}




